<template>
  <div class="page-container">
    <!-- 背景图容器 -->
    <div class="top-info">
      <div class="content-wrapper">
        <div class="left-box">
          <!-- 下拉组件 -->
          <el-dropdown>
            <span class="dropdown-trigger">
              工单任务：检测水样任务 
              <el-icon class="arrow-icon"><arrow-down /></el-icon>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>检测光谱任务</el-dropdown-item>
                <el-dropdown-item>检测色谱任务</el-dropdown-item>
                <el-dropdown-item>检测水样任务</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
        <div class="right-box">
          <div class="time-wrapper">
            <div class="time-box">
              <span class="label">实际执行时间：</span>
              <span class="time-segment">{{ hours }}</span> :
              <span class="time-segment">{{ minutes }}</span> :
              <span class="time-segment">{{ seconds }}</span>
            </div>
          </div>
          <div class="time-wrapper">
            <div class="time-box">
              <span class="label">运行倒计时：</span>
              <span class="time-segment">00</span> :
              <span class="time-segment">00</span> :
              <span class="time-segment">00</span>
            </div>
          </div>
          <el-button type="primary" @click="startTimer">开始计时</el-button>
        </div>
      </div>
    </div>
    
    <!-- 父容器：占满网页 -->
    <div class="parent-container">
      <!-- 主内容盒子 -->
      <div class="box2">
        <!-- 样本详情盒子：占65%宽度 -->
        <div class="sample-detail-box">
          <!-- 顶部标题区域 -->
          <div class="top-section">
            <div class="top-left">
              <div class="title-box">样本组详情</div>
            </div>
            <div class="top-right">
              <div class="slider-selector">
                <span
                  :class="currentTab === 'sampleList' ? 'slider-item active' : 'slider-item'"
                  @click="currentTab = 'sampleList'"
                >
                  样本列表
                </span>
                <span
                  :class="currentTab === 'sampleTray' ? 'slider-item active' : 'slider-item'"
                  @click="currentTab = 'sampleTray'"
                >
                  进样盘
                </span>
              </div>
            </div>
          </div>
          
          <!-- 中间表单区域 -->
          <div class="middle-section">
            <el-row :gutter="20" class="form-row">
              <el-col :span="6">
                <el-form-item label="实验阶段">
                  <el-input v-model="formData.stage" readonly />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="样本数量">
                  <el-input v-model="formData.quantity" readonly />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="待处理">
                  <el-input v-model="formData.pending" readonly />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="已完成">
                  <el-input v-model="formData.completed" readonly />
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          
          <!-- 底部表格区域（带滚动条） -->
          <div class="bottom-section">
            <div class="table-scroll-container">
              <el-table :data="sampleData" border size="small">
                <el-table-column prop="id" label="样本id" align="center" />
                <el-table-column prop="name" label="样品名称" align="center" />
                <el-table-column prop="testItem" label="检测项" align="center" />
                <el-table-column prop="source" label="样本来源" align="center" />
                <el-table-column prop="method" label="方法名称" align="center" />
                <el-table-column prop="position" label="位置" align="center" />
                <el-table-column prop="samplingPoint" label="取样点名称" align="center" />
              </el-table>
            </div>
          </div>
        </div>
        
        <!-- 右侧盒子：占35%宽度 -->
        <div class="right-side-box">
          <!-- 右侧上方盒子：设备日志 -->
          <div class="right-top-part">
            <div class="right-top-section">
              <span>设备日志</span>
            </div>
            <div class="right-bottom-section">
              <div class="right-bottom-box" v-for="(item, index) in deviceLogs" :key="index">
                <span>水质</span>
                <span>2025-08-08</span>
                <span>S15中间稀释容盐酸</span>
              </div>
            </div>
          </div>
          
          <!-- 右侧下方盒子：耗材监控 -->
          <div class="right-bottom-part">
            <div class="right-bottom-top-section">
              <span>耗材监控</span>
            </div>
            <div class="right-bottom-form-section">
              <el-table :data="consumableData" border size="small">
                <el-table-column prop="name" label="名称" align="center" />
                <el-table-column prop="usage" label="用量/总量" align="center" />
                <el-table-column label="操作" align="center">
                  <!-- <template #default="scope"> -->
                  <template>
                    <el-button type="primary" size="small">更换</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { 
  ElButton, ElInput, ElFormItem, ElRow, ElCol, 
  ElTable, ElTableColumn, ElDropdown, ElDropdownMenu,
  ElDropdownItem, ElIcon
} from 'element-plus'
import { ArrowDown } from '@element-plus/icons-vue'

// 时间状态管理
const hours = ref('00')
const minutes = ref('00')
const seconds = ref('00')
let timer = null

// 开始计时方法
const startTimer = () => {
  if (timer) clearInterval(timer)
  let totalSeconds = 0
  timer = setInterval(() => {
    totalSeconds++
    hours.value = String(Math.floor(totalSeconds / 3600)).padStart(2, '0')
    minutes.value = String(Math.floor((totalSeconds % 3600) / 60)).padStart(2, '0')
    seconds.value = String(totalSeconds % 60).padStart(2, '0')
  }, 1000)
}

// 标签切换状态
const currentTab = ref('sampleList')

// 表单数据
const formData = ref({
  stage: '待处理',
  quantity: '0',
  pending: '25',
  completed: '0'
})

// 样本表格数据（新增3条数据，共7条）
const sampleData = ref([
  { id: '448437', name: 'RCP6307-101', testItem: 'PH', source: 'lims同步', method: '-', position: '1', samplingPoint: '14CA1313' },
  { id: '448438', name: 'RCP6307-102', testItem: 'PH', source: 'lims同步', method: '-', position: '2', samplingPoint: '14CA1314' },
  { id: '448439', name: 'RCP6307-103', testItem: 'PH', source: 'lims同步', method: '-', position: '3', samplingPoint: '14CA1315' },
  { id: '448440', name: 'RCP6307-104', testItem: 'PH', source: 'lims同步', method: '-', position: '4', samplingPoint: '14CA1316' },
  { id: '448441', name: 'RCP6307-105', testItem: 'PH', source: 'lims同步', method: '-', position: '5', samplingPoint: '14CA1317' },
  { id: '448442', name: 'RCP6307-106', testItem: 'PH', source: 'lims同步', method: '-', position: '6', samplingPoint: '14CA1318' },
  { id: '448443', name: 'RCP6307-107', testItem: 'PH', source: 'lims同步', method: '-', position: '7', samplingPoint: '14CA1319' },
  { id: '448441', name: 'RCP6307-105', testItem: 'PH', source: 'lims同步', method: '-', position: '5', samplingPoint: '14CA1317' },
  { id: '448442', name: 'RCP6307-106', testItem: 'PH', source: 'lims同步', method: '-', position: '6', samplingPoint: '14CA1318' },
  { id: '448443', name: 'RCP6307-107', testItem: 'PH', source: 'lims同步', method: '-', position: '7', samplingPoint: '14CA1319' }
])

// 设备日志数据
const deviceLogs = ref([
  { type: '水质', date: '2025-08-08', content: 'S15中间稀释容盐酸' },
  { type: '水质', date: '2025-08-08', content: 'S15中间稀释容盐酸' },
  { type: '水质', date: '2025-08-08', content: 'S15中间稀释容盐酸' },
  { type: '水质', date: '2025-08-08', content: 'S15中间稀释容盐酸' }
])

// 耗材监控数据
const consumableData = ref([
  { name: '1ml tips', usage: '1/96个' },
  { name: '5ml tips', usage: '0/120个' },
  { name: '4ml tips', usage: '2/84个' }
])
</script>

<style scoped>
/* 页面容器样式 */
.page-container {
  width: 100%;
  margin: 0;
  padding: 0;
}

/* 顶部信息栏样式 */
.top-info {
  width: 100%;
  height: 230px;
  background: url('@/views/image/picture.png') no-repeat center/cover;
  display: flex;
  justify-content: center;
  align-items: center;
}

.content-wrapper {
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 0 20px;
  box-sizing: border-box;
}

.left-box {
  display: flex;
  align-items: flex-start;
  padding: 20px;
  width: 50%;
}

.dropdown-trigger {
  display: flex;
  align-items: center;
  font-size: 28px;
  font-weight: 700;
  color: #000;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
  cursor: pointer;
}

.arrow-icon {
  margin-left: 8px;
  transition: transform 0.3s;
}

:deep(.el-dropdown-open .arrow-icon) {
  transform: rotate(180deg);
}

.right-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 20px;
  width: 50%;
  box-sizing: border-box;
}

.time-wrapper {
  margin-bottom: 10px;
}

.time-box {
  display: flex;
  align-items: center;
  background-color: #fff;
  padding: 6px 12px;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.label {
  font-size: 16px;
  color: #333;
  margin-right: 8px;
  font-weight: 500;
}

.time-segment {
  display: inline-block;
  width: 36px;
  text-align: center;
  background-color: #f0f0f0;
  color: #333;
  border-radius: 3px;
  margin: 0 3px;
  padding: 3px 0;
  font-weight: 600;
}

.el-button {
  margin-top: 10px;
  padding: 8px 16px;
}

/* 主内容区域样式 */
.parent-container {
  width: 100%;
  min-height: calc(100vh - 230px);
  margin-top: 0;
  padding: 20px;
  box-sizing: border-box;
  background-color: #f5f7fa;
}

.box2 {
  width: 100%;
  border: 1px solid #e8e8e8;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  background-color: #fff;
  min-height: 650px; /* 增加主容器高度，避免挤压 */
}

/* 样本详情区域 */
.sample-detail-box {
  width: 65%;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.top-section {
  height: 60px;
  display: flex;
  align-items: center;
}

.top-left {
  width: 50%;
  display: flex;
  align-items: center;
}

.title-box {
  font-size: 20px;
  font-weight: 600;
  color: #333;
}

.top-right {
  width: 50%;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.slider-selector {
  display: flex;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  overflow: hidden;
}

.slider-item {
  padding: 6px 18px;
  cursor: pointer;
  background-color: #f5f7fa;
  transition: all 0.3s;
}

.slider-item.active {
  background-color: #fff;
  border: 2px solid #409eff;
  border-top: none;
  border-bottom: none;
  font-weight: 500;
  color: #409eff;
}

.middle-section {
  padding: 20px;
  background-color: #f9f9f9;
  border-radius: 4px;
  flex-shrink: 0;
}

.form-row {
  width: 100%;
}

/* 表格滚动容器（核心修改） */
.bottom-section {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.table-scroll-container {
  flex-grow: 1;
  overflow-y: auto; /* 超出高度显示垂直滚动条 */
  max-height: 400px; /* 限制表格最大高度，确保不挤压其他区域 */
}

:deep(.el-table) {
  width: 100%;
  border-collapse: collapse;
}

:deep(.el-table__row) {
  height: 50px;
}

:deep(.el-form-item) {
  margin-bottom: 0;
}

:deep(.el-form-item__label) {
  font-weight: 500;
  padding-right: 10px;
}

:deep(.el-input__inner) {
  height: 40px;
}

/* 右侧盒子样式（修复耗材监控显示） */
.right-side-box {
  width: 35%;
  display: flex;
  flex-direction: column;
  padding-left: 20px;
  box-sizing: border-box;
  gap: 20px;
}

/* 设备日志区域（60%高度） */
.right-top-part {
  flex: 6;
  display: flex;
  flex-direction: column;
}

.right-top-section {
  height: 30%;
  background-color: #f9f9f9;
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 18px;
  font-weight: 600;
  border-radius: 4px 4px 0 0;
  border: 1px solid #e8e8e8;
  border-bottom: none;
}

.right-bottom-section {
  height: 70%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 15px 0;
  border: 1px solid #e8e8e8;
  border-top: none;
  border-radius: 0 0 4px 4px;
}

.right-bottom-box {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 22%;
  background-color: #fff;
  border: 1px solid #f0f0f0;
  border-radius: 4px;
  margin: 0 10px;
  padding: 10px;
}

/* 耗材监控区域 */
.right-bottom-part {
  flex: 4;
  display: flex;
  flex-direction: column;
  min-height: 250px; /* 固定最小高度，确保内容完整显示 */
}

.right-bottom-top-section {
  height: 30%; /* 调整标题高度比例 */
  background-color: #f9f9f9;
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 18px;
  font-weight: 600;
  border-radius: 4px 4px 0 0;
  border: 1px solid #e8e8e8;
  border-bottom: none;
}

.right-bottom-form-section {
  height: 70%; /* 调整表格高度比例 */
  border: 1px solid #e8e8e8;
  border-radius: 0 0 4px 4px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

:deep(.right-bottom-form-section .el-table) {
  flex-grow: 1;
}

/* 响应式调整 */
@media (max-width: 1200px) {
  .box2 {
    flex-direction: column;
  }
  
  .sample-detail-box, .right-side-box {
    width: 100%;
  }
  
  .right-side-box {
    padding-left: 0;
    margin-top: 20px;
  }
}
</style>